package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcOldManAccountFundsMapper;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.domain.OmcOldManAccountFunds;
import com.csun.cmny.provider.service.OmcOldManAccountFundsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author chenzheng
 * @description:老人账户资金表服务层
 * @date 2019/8/26 16:38
 */
@Slf4j
@Service
@Transactional
public class OmcOldManAccountFundsServiceImpl extends BaseService<OmcOldManAccountFunds>
        implements OmcOldManAccountFundsService {

    @Resource
    private OmcOldManAccountFundsMapper omcOldManAccountFundsMapper;

    /**
     * 根据Id查询老人的资金账户
     *
     * @param oldmanId the oldman id
     * @return the oldman account funds
     */
    @Override
    public OmcOldManAccountFunds queryByOldmanId(Integer oldmanId) {

        OmcOldManAccountFunds omcOldManAccountFunds = new OmcOldManAccountFunds();
        omcOldManAccountFunds.setOldManId((long) oldmanId);

        try {
            omcOldManAccountFunds = omcOldManAccountFundsMapper.selectOne(omcOldManAccountFunds);
        } catch (Exception e) {
            throw new OmcBizException(ErrorCodeEnum.OMC10038029);
        }

        return omcOldManAccountFunds;
    }

    @Override
    public int updatePrice(OmcOldManAccountFunds omcOldManAccountFunds){
        return omcOldManAccountFundsMapper.updatePrice(omcOldManAccountFunds);
    }
}
